home *** CD-ROM | disk | FTP | other *** search
/ Aminet 35 / Aminet 35 (2000)(Schatztruhe)[!][Feb 2000].iso / Aminet / dev / src / BernieHeaders.lha / include / DebugMacros.h < prev    next >
Encoding:
C/C++ Source or Header  |  1999-12-06  |  3.7 KB  |  135 lines

  1. #ifndef DEBUGMACROS_H
  2. #define DEBUGMACROS_H
  3. /*
  4. **    $Id: DebugMacros.h,v 1.2 1999/02/07 14:41:01 bernie Exp $
  5. **
  6. **    Copyright (C) 1995,96,97,98,99 Bernardo Innocenti <bernardo.innocenti@usa.net>
  7. **    All rights reserved.
  8. **
  9. **    Use 4 chars wide TABs to read this file
  10. **
  11. **    Some handy debug macros which are automatically excluded when the
  12. **    _DEBUG preprocessor symbol isn't defined. To make debug executables,
  13. **    you must link with debug.lib or any module containing the kprintf()
  14. **    function.
  15. **
  16. **    Here is a short description of the macros defined below:
  17. **
  18. **    ILLEGAL
  19. **        Output an inline "ILLEGAL" 68K opcode, which will
  20. **        be interpreted as a breakpoint by most debuggers.
  21. **
  22. **    DBPRINTF
  23. **        Output a formatted string to the debug console. This
  24. **        macro uses the debug.lib kprintf() function by default.
  25. **
  26. **    ASSERT(x)
  27. **        Do nothing if the expression <x> evalutates to a
  28. **        non-zero value, output a debug message otherwise.
  29. **
  30. **    ASSERT_VALID_PTR(x)
  31. **        Checks if the expression <x> points to a valid
  32. **        memory location, and outputs a debug message
  33. **        otherwise. A NULL pointer is considered VALID.
  34. **
  35. **    ASSERT_VALID_PTR_OR_NULL(x)
  36. **        Checks if the expression <x> points to a valid
  37. **        memory location, and outputs a debug message
  38. **        otherwise. A NULL pointer is considered INVALID.
  39. **
  40. **    DB(x)
  41. **        Compile the expression <x> when making a debug
  42. **        executable, otherwise omit it.
  43. **
  44. **    DB1(x)
  45. **        DB verbosity level 1. Compile the expression <x> when the
  46. **        preprocessor symbol DEBUG is defined to a number greater or
  47. **        equal to 1.
  48. **
  49. **    DB2(x)
  50. **        DB verbosity level 2. Compile the expression <x> when the
  51. **        preprocessor symbol _DEBUG is defined to a number greater or
  52. **        equal to 2.
  53. */
  54.  
  55. #if (defined(_DEBUG) && (_DEBUG != 0)) || (defined(DEBUG) && (DEBUG != 0))
  56.  
  57.     /* Needed for TypeOfMem() */
  58.     #ifndef  PROTO_EXEC_H
  59.     #include <proto/exec.h>
  60.     #endif /* PROTO_EXEC_H */
  61.  
  62.     #if defined(__SASC)
  63.  
  64.         extern void __builtin_emit (int);
  65.         // #define ILLEGAL __builtin_emit(0x4AFC)
  66.         #define ILLEGAL 0
  67.         STDARGS extern void kprintf (const char *, ...);
  68.  
  69.     #elif defined(__GNUC__)
  70.  
  71.         /* Currently, there is no kprintf() in libamiga.a */
  72.         #define kprintf printf
  73.  
  74.         /* GCC doesn't accept asm statements in the middle of an
  75.          * expression such as `a ? b : asm("something")'.
  76.          */
  77.         #define ILLEGAL illegal()
  78.         static __inline__ int illegal(void) { asm ("illegal"); return 0; }
  79.         extern void STDARGS FORMATCALL(printf,1,2) kprintf (const char *, ...);
  80.  
  81.     #else
  82.         #error Please add compiler specific definitions for your compiler
  83.     #endif
  84.  
  85.  
  86.     /* common definitions for ASSERT and DB macros */
  87.  
  88.     #define DBPRINTF kprintf
  89.  
  90.     #define ASSERT(x) ( (x) ? 0 :                                    \
  91.         ( DBPRINTF ("\x07%s, %ld: assertion failed: " #x "\n",        \
  92.         __FILE__, __LINE__) , ILLEGAL ) );
  93.  
  94.     #define ASSERT_VALID_PTR_OR_NULL(x) ( ((((APTR)(x)) == NULL) ||    \
  95.         (((LONG)(x) > 1024) &&    TypeOfMem ((APTR)(x)))) ? 0 :        \
  96.         ( DBPRINTF ("\x07%s, %ld: bad pointer: " #x " = $%lx\n",    \
  97.         __FILE__, __LINE__, (APTR)(x)) , ILLEGAL ) );
  98.  
  99.     #define ASSERT_VALID_PTR(x) ( (((LONG)(x) > 1024) &&            \
  100.         TypeOfMem ((APTR)(x))) ? 0 :                                \
  101.         ( DBPRINTF ("\x07%s, %ld: bad pointer: " #x " = $%lx\n",    \
  102.         __FILE__, __LINE__, (APTR)(x)) , ILLEGAL ) );
  103.  
  104.     /* Obsolete definitions */
  105.     #define ASSERT_VALID    ASSERT_VALID_PTR_OR_NULL
  106.     #define ASSERT_VALIDNO0    ASSERT_VALID_PTR
  107.  
  108.     #define DB(x) x
  109.     #define DB1(x) x
  110.  
  111.     #if (_DEBUG >= 2) || (DEBUG >= 2)
  112.         #define DB2(x) x
  113.     #else
  114.         #define DB2(x)
  115.     #endif
  116.  
  117.     #if (_DEBUG >= 3) || (DEBUG >= 3)
  118.         #define DB3(x) x
  119.     #else
  120.         #define DB3(x)
  121.     #endif
  122. #else
  123.     #define ASSERT_VALID_PTR(x)
  124.     #define ASSERT_VALID_PTR_OR_NULL(x)
  125.     #define ASSERT_VALID(x)
  126.     #define ASSERT_VALIDNO0(x)
  127.     #define ASSERT(x)
  128.     #define DB(x)
  129.     #define DB1(x)
  130.     #define DB2(x)
  131.     #define DB3(x)
  132. #endif /* DEBUG */
  133.  
  134. #endif /* !DEBUGMACROS_H */
  135.